import { ok, fail } from '../utils/response'
import storeShopFoodRepository, { StoreShopFoodRow } from '../database/repositories/storeShopFoodRepository'
import storeShopFoodBindRepository, { StoreShopFoodBindRow } from '../database/repositories/storeShopFoodBindRepository'
import storeShopFoodSkuRepository, { StoreShopFoodSkuRow } from '../database/repositories/storeShopFoodSkuRepository'

/**
 * 菜品域服务（仅保留“批量新增/更新”能力）
 * - foods：菜品基础信息
 * - foodBind：门店绑定菜品（估清/库存）
 * - foodSku：菜品规格/价格
 */
export class FoodDomainService {
    /** 批量新增/更新 菜品 */
    static foodBatchUpsert(rows: StoreShopFoodRow[]) {
        try {
            storeShopFoodRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            return fail(e?.message || 'food batch upsert failed')
        }
    }

    /** 批量新增/更新 门店-菜品绑定（估清） */
    static foodBindBatchUpsert(rows: StoreShopFoodBindRow[]) {
        try {
            storeShopFoodBindRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            return fail(e?.message || 'food bind batch upsert failed')
        }
    }

    /** 批量新增/更新 菜品SKU */
    static foodSkuBatchUpsert(rows: StoreShopFoodSkuRow[]) {
        try {
            storeShopFoodSkuRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            return fail(e?.message || 'food sku batch upsert failed')
        }
    }
}

export default FoodDomainService


